﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="PersonalityList.aspx.cs" Inherits="Assesment.Web.Lists.Administration.Catalog.PersonalityList" %>

<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
     <script src="<%= ResolveUrl("~/scripts/jquery.msgBox.v1.js") %>" type="text/javascript"></script>

    <div class="side-content fr">
        <div class="content-module">
            <div class="content-module-heading cf">
                <h3 class="fl">
                    Kepribadian</h3>
                <span class="fr expand-collapse-text">Click to collapse</span> <span class="fr expand-collapse-text initial-expand">
                    Click to expand</span>
            </div>
            <!-- end content-module-heading -->
            <div class="content-module-main">
                <div>
                    <button id="btnAdd" type="button" onclick="OpenForm('add');">
                        Tambah</button>
                    <button id="btnEdit" type="button" onclick="OpenForm('edit');">
                        Ubah</button>
                    <button id="btnDelete" type="button" onclick="OpenForm('delete');">
                        Hapus</button>
                </div>
                <br />
                <%--<div style="overflow: auto; height: 350px;">--%>
                <table id="table" class="scroll" cellpadding="0" cellspacing="0">
                </table>
                <div id="pager" class="scroll">
                </div>
                <br />
                <div id="dialog" title="Default dialog">
                </div>
                <%--</div>--%>
            </div>
            <!-- end content-module-main -->
        </div>
    </div>
     <script type="text/javascript">

         $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
         $("#btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
         $("#btnDelete").button({ icons: { primary: "ui-icon-trash"} });

    </script>

    <script type="text/javascript">

        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Administration/Catalog/Personalityhandler.ashx") %>';

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['ID', 'Code','Disc','Tipe'],
            colModel: [
                { name: 'PersonalityID', key: true, hidden: true, index: 'PersonalityID', width: 60 },
                { name: 'Code', index: 'Code', align: 'center', width: 50, search:false },
                { name: 'Disc', index: 'Disc', align: 'center', width: 100, searchoptions: { sopt: ['cn', 'eq']} },
                { name: 'Type', index: 'Type', align: 'left', width: 300, searchoptions: { sopt: ['cn', 'eq']} }

           	],
            rownumbers: true,
            rowNum: 10,
            id: 'PersonalityID',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'Code',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 700,
            height: '100%',
            caption: 'Kepribadian',
            excel: true,
            ajaxGridOptions: { cache: false }
        });

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: false, closeAfterSearch: true });

        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/administration/catalog/Personalityform.aspx") %>';

            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'PersonalityID'));
            });


            if (ctl == 'edit') {
                if (selIds.length == 0) {
                    //alert('Pilih data yang mau di ubah !');
                    $.msgBox("Pilih data yang mau di ubah !", null, { title: "Pesan" });
                }
                else if (selIds.length > 1) {
                    // alert('Pilih satu record untuk ubah data.');
                    $.msgBox("Pilih satu record untuk ubah data", null, { title: "Pesan" });
                }
                else {
                    $('#dialog').load(formUrl + '?id=' + selText + '&menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 700, height: 500, title: 'Ubah Kepribadian' });
                    $("#dialog").dialog('open');
                }
            }
            else if (ctl == 'add') {
                $('#dialog').load(formUrl + '?menuId=' + '<%= base.MenuID %>').dialog({ autoOpen: false, modal: true, width: 700, height: 500, title: 'Tambah Kepribadian' });
                $("#dialog").dialog('open');
            }
            else {
                if (selIds.length == 0)
                //alert('Pilih data yang mau di hapus !');
                    $.msgBox("Pilih data yang mau di hapus !", null, { title: "Pesan" });
                else {


                    $.msgBox.confirm("Benar data akan di hapus ?", function () {
                        var objDeparment = new Object();
                        objDeparment.ID = encodeURIComponent(selText);
                        jsonData = JSON.stringify(objDeparment);
                        CallAjax('<%= ResolveUrl("~/ajaxhandler/administration/catalog/Personalityhandler.ashx") %>', "?method=delete", jsonData);
                        setTimeout("$('#table').trigger('reloadGrid');", 3000);
                    }, false);
                }
            }

        }
    
    </script>

</asp:Content>

